package com.xy.shop.wechat.controller;

import com.xy.shop.web.controller.BaseController;
import com.xy.shop.wechat.service.Gzh1WxService;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/wechat/porta2/")
public class CreateMenuController extends BaseController {

	 @Resource
	 private Gzh1WxService wxService;

	public WxMenu createMenu() {

		WxMenu menu = new WxMenu();
        WxMenuButton button1 = new WxMenuButton();
        button1.setType(WxConsts.MenuButtonType.VIEW);
        button1.setName("游戏下载");
        button1.setUrl("http://lwdownload.jiaheyx.com/kx.html");
    

        WxMenuButton button2 = new WxMenuButton();
        button2.setName("诚招代理");

        WxMenuButton button21 = new WxMenuButton();
        button21.setType(WxConsts.MenuButtonType.VIEW);
        button21.setName("公司简介");
        button21.setUrl("http://mp.weixin.qq.com/s/1waOilL0eHTdqwGHHwz5Jw");
       

      
        WxMenuButton button22 = new WxMenuButton();
        button22.setType(WxConsts.MenuButtonType.VIEW);
        button22.setName("代理商后台");
        button22.setUrl("https://gc.jiaheyx.com/cc/login.html");

        
        WxMenuButton button3 = new WxMenuButton();
        button3.setName("联系客服");
        
        WxMenuButton button31 = new WxMenuButton();
        button31.setType(WxConsts.MenuButtonType.VIEW);
        button31.setName("最新活动");
        button1.setUrl("https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI1OTY0NTM0OQ==&scene=124#wechat_redirect");
        /*button31.setUrl(wxService.oauth2buildAuthorizationUrl
                ("https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzU1ODAxMTY1MQ==#wechat_redirect", "state", null));*/

        WxMenuButton button32 = new WxMenuButton();
        button32.setType(WxConsts.MenuButtonType.CLICK);
        button32.setName("联系客服");
        button32.setKey("请点击左下角小键盘输入您要咨询的问题，客服人员将会及时回复您！");
      /*  button32.setUrl("http://19j1v52321.iok.la/wechat/wechat/portal/lwhy");*/
       /* button32.setUrl(wxService.oauth2buildAuthorizationUrl
                ("https://gc.jiaheyx.com/cc/login.html", "state", null));*/


  

        button2.getSubButtons().add(button21);
        button2.getSubButtons().add(button22);
        button3.getSubButtons().add(button31);
        button3.getSubButtons().add(button32);
        menu.getButtons().add(button1);
        menu.getButtons().add(button2);
        menu.getButtons().add(button3);
        
        return menu;
		
	}

    //制作菜单
	@ResponseBody
	@RequestMapping("createMenu.do")
    public void makeMenus() throws WxErrorException {
		wxService.getMenuService().menuCreate(createMenu());
    }
    
}
